<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>找回密码页面</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/log2.jpg" alt="">
        <a href="blog_list.html" class="title">博客系统主页</a>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="myblog_list.html">主页</a>
        <a href="blog_add.html">写博客</a>
        <a href="reg.html">注册</a>
        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="login-container">
        <!-- 中间的登陆框 -->
        <div class="login-dialog">
            <h3>找回密码</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username">
            </div>
            <div class="row">
                <span>验证手机号</span>
                <input type="text" id="phonenumber">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password">
            </div>
            <div class="row">
                <span>确认密码</span>
                <input type="password" id="password2">
            </div>
            <div class="row" id="regAndlogin">
                <button onclick="location.href='login.html'">返回</button>
                <button id="submit" onclick="mysub()">确认修改</button>
            </div>
        </div>
    </div>
    <script>
        function mysub() {
            //1.非空校验
            var username = jQuery('#username');
            var phonenumber = jQuery('#phonenumber');
            var password = jQuery('#password');
            var password2 = jQuery('#password2');
            if (username.val() == '') {
                alert("用户名不能为空");
                //将用户的光标设置到此行
                username.focus();
                return;
            }
            if (password.val() == '') {
                alert("密码不能为空")
                //将用户的光标设置到此行
                password.focus();
                return;
            }
            if (password2.val() == '') {
                alert("确认密码不能为空");
                //将用户的光标设置到此行
                password2.focus();
                return;
            }
            if (phonenumber.val() == '') {
                alert("手机号不能为空,用于修改/找回密码!");
                //将用户的光标设置到此行
                phonenumber.focus();
                return;
            }
            if (phonenumber.val().length < 11 || phonenumber.val().length > 11) {
                alert("非法号码,请重新填写!");
                //将用户的光标设置到此行
                phonenumber.focus();
                return;
            }
            //2.判断两次密码是否一致
            if (password.val() != password2.val()) {
                alert("两次输入的密码不一致!")
                return;
            }


            //2.ajax请求登录结果
            jQuery.ajax({
                type: "post",
                url: "/user/findpsw",
                data: { "username": username.val(), "phonenumber": phonenumber.val(), "password": password.val() },
                success: function (result) {
                    if (result != "" && result.code == 200 && result.data != null) {
                        //修改密码成功
                        alert("修改密码成功!")
                        location.href = "login.html";
                    } else {
                        alert("验证失败!请检查用户名和手机号!")
                    }
                }
            })
        }
    </script>
</body>

</html>